See if this helps you see how this could be done. Source PD Instance would send Webhook V2 (you should really use Webhook v3) to AWS Lambda that would parse the trigger webhook and build a new incident payload to create an incident in the target PD instance on a given service. You could get much more elaborate with how you evaluate the incoming webhook and decide what service to send it to in target, what priority, what EP to use, etc.
NOTE: I didn’t test this code!
#!/usr/bin/env python
from botocore.vendored import requests
import json
# use env variables or KMS
PD_API_key = "FOO" #target RW API token
API_user = "FOO@BAR.COM" #target user email for inc creation
def createIncidentInTarget(serviceID,priorityID,incID,incTitle,incBody):
headers = {'Content-Type': 'application/json', 'Accept': 'application/vnd.pagerduty+json;version=2',
'From': API_user, 'Authorization': 'Token token=' + PD_API_key}
payload = createIncidentPayload(serviceID,priorityID,incID,incTitle,incBody)
endpoint = 'https://api.pagerduty.com/incidents'
resp = requests.post(endpoint, headers=headers, data=json.dumps(payload))
json_resp = resp.json()
print(json_resp)
return json_resp
def createIncidentPayload(serviceID,priorityID,incID,incTitle,incBody):
payload = {
"incident": {
"type": "incident",
"title": incTitle, #source inc title
"service": {
"id": serviceID, #target serviceID
"type": "service_reference"
},
"priority": {
"id": priorityID, #target priorityID
"type": "priority_reference"
},
"urgency": "high",
"incident_key": incID, #source-serviceID-source-incID
"body": {
"type": "incident_body",
"details": incBody #source inc body
}
}
}
return payload
def lambda_handler(event, context):
# trigger a new incident in target based on source inc webhook data
if event['detail']['event'] == "incident.trigger": #only for trigger incidents from source
# source incident ID
incID = event['detail']['incident']['id']
# source incident title
incTitle = event['detail']['incident']['summary']
# source incident body
incBody = event['detail']['log_entries']['channel']['details']
# target service ID
serviceID = "P12345"
# target priority ID
targetP1 = "P98765"
targetP2 = "P99887"
if event['detail']['incident']['priority']['summary'] == 'P1':
createIncidentInTarget(serviceID,targetP1,incID,incTitle,incBody)
if event['detail']['incident']['priority']['summary'] == 'P2':
createIncidentInTarget(serviceID,targetP2,incID,incTitle,incBody)
return 1